//
//  AppCell.m
//  LimitFree
//
//  Created by LZXuan on 15-6-8.
//  Copyright (c) 2015年 轩哥. All rights reserved.
//

#import "AppCell.h"
#import "UIImageView+WebCache.h"

@implementation AppCell

- (void)awakeFromNib {
    //xib 初始化
    self.iconImageView.layer.masksToBounds = YES;
    self.iconImageView.layer.cornerRadius = 8;
    
    self.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"appproduct_loadingviewcell_ligh_2t"]];
    
    //创建一个黑线 粘贴到价格label
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.priceLabel.frame.size.height/2, self.priceLabel.frame.size.width, 1)];
    lineView.backgroundColor = [UIColor blackColor];
    [self.priceLabel addSubview:lineView];
}


//当点击cell(高亮)/选中cell的 系统 默认会把cell 的contentView的上面的所有子视图的背景设置为clearColor
//解决方法 就是选中cell 和点击cell(高亮状态) 把contentView的子视图背景颜色 不改变

//选中cell 的调用
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    UIView *line = self.priceLabel.subviews[0];
    //保持背景颜色不变
    line.backgroundColor = [UIColor blackColor];
}
//点击cell(高亮状态的时候调用)
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    [super setHighlighted:highlighted animated:animated];
    UIView *line = self.priceLabel.subviews[0];
    //保持背景颜色不变
    line.backgroundColor = [UIColor blackColor];
}




- (void)showDataWithModel:(AppModel *)model indexPath:(NSIndexPath *)indexPath{
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.iconUrl] placeholderImage:[UIImage imageNamed: @"topic_Header"]];
    self.nameLabel.text = [NSString stringWithFormat:@"%ld.%@",indexPath.row+1,model.name];
    
    self.priceLabel.text = [NSString stringWithFormat:@"%.2f",model.lastPrice.doubleValue];//最后价格
    
    self.categoryLabel.text = model.categoryName;//分类名字 （Game）
    [self.starLevelView setStarLevel:model.starCurrent.doubleValue];
    self.shardsLabel.text = [NSString stringWithFormat:@"分享:%@ 收藏:%@ 下载:%@",model.shares,model.favorites,model.downloads];
    //第二个label 不同界面显示不一样
    if ([self.category isEqualToString:kLimitType]) {
        self.typeLabel.text = [NSString stringWithFormat:@"剩余:%@",[LZXHelper stringNowToDate:model.expireDatetime formater:@"yyyy-MM-dd HH:mm:ss.0"]];
    }else if ([self.category isEqualToString:kReduceType]) {
        self.typeLabel.text = [NSString stringWithFormat:@"现价:%.2f",model.currentPrice.doubleValue];
    }else {
        self.typeLabel.text = [NSString stringWithFormat:@"评分:%.1f",model.starCurrent.doubleValue];
    }
    
    if (indexPath.row%2) {
        self.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"cate_list_bg1"]];
    }else{
        self.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"cate_list_bg2"]];
    }
}


@end
